﻿@{
    Layout = "~/Views/Shared/_LayoutPartial.cshtml";
}
<script type="text/javascript">
    $(function() {
        InitGird();
        $("#searchBtn").live('click', function () {

            var WorkType = $('#WorkType').val();
            //var QuestionType = $('#QuestionType').val();
            var QuestionType = $("#QuestionType").combobox('getValue');
            var Content = $('#Content').val();
            $('#tab_list').datagrid('options').url = "GetQuestionList";
            $('#tab_list').datagrid('load', {
                worktype: WorkType,
                questiontype: QuestionType,
                content: Content
            });
        });
    });

    //初始化表格
    function InitGird() {
        var grid = $('#tab_list').datagrid({
            title: '题目列表', //表格标题
            url: 'GetQuestionList', //请求数据的页面
            idField: 'Id', //标识字段,主键
            nowrap: false, //是否换行，True 就会把数据显示在一行里
            striped: true, //True 奇偶行使用不同背景色
            collapsible: true, //可折叠
            remoteSort: true, //定义是否从服务器给数据排序
            singleSelect: true,
            columns: [
                [
                    { title: 'Id', field: 'Id', width: 1, hidden: true },
                    { title: '工种', field: 'WorkType', width: 150 },
                    {
                        title: '问题类型',
                        field: 'QuestionType',
                        width: 100,
                        formatter: function(value, row, index) {
                            if (value == 1)
                                return "文本题";
                            else if (value == 2)
                                return "图片题";
                            else if (value == 3)
                                return "视频题";
                        }
                    },
                    { title: '问题描述', field: 'Content', width: 600 },
                    { title: '其他信息', field: 'OtherInfo', width: 400 },
                    { title: '正确答案', field: 'Answer', width: 80 }
                ]
            ],
            toolbar: [
                {
                    id: 'btnadd',
                    text: '添加',
                    iconCls: 'icon-add',
                    handler: function() {
                        if (parent)
                            parent.addTab("添加问题", "/Manage/CreateQuestion", "icon-add");
                    }
                },
                {
                    id: 'btnedit',
                    text: '编辑',
                    iconCls: 'icon-picture_edit',
                    handler: function() {
                        var row = grid.datagrid('getSelected');
                        if (row && row.Id > 0) {
                            if (parent)
                                parent.addTab("修改问题", "/Manage/CreateQuestion?QID=" + row.Id, "icon-picture_edit");
                        } else
                            $.messager.alert("提示", "请至少选择一行", "error");
                    }
                },
                {
                    id: 'btndelete',
                    text: '删除',
                    iconCls: 'icon-delete',
                    handler: function() {
                        var row = grid.datagrid('getSelected');
                        if (row && row.Id > 0) {
                            $.messager.confirm("操作提示", "您确定要执行操作吗？", function(data) {
                                if (data) {
                                    $.post("/Manage/DeleteQuestion", { QID: row.Id }, function(result) {
                                        if (!result)
                                            $.messager.alert("提示", "删除失败", "error");
                                        else {
                                            $.messager.alert("提示", "删除成功", "info");
                                            grid.datagrid('reload');
                                            grid.datagrid('clearSelections');
                                        }
                                    });
                                }
                            });
                        } else
                            $.messager.alert("提示", "请至少选择一行", "error");
                    }
                }
            ],
            queryParams: { "ispro": false },
            pagination: true, //是否开启分页
            pageNumber: 1, //默认索引页
            pageSize: 20, //默认一页数据条数
            rownumbers: true //行号
        });
    }

   
</script>
<div style="height: auto; margin: 5px 0px 10px 0px">
    
    <fieldset>
        <legend>查询</legend>
        工种：<input type="text" class="easyui-text" id="WorkType"/>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        问题类型：
        <select class="easyui-combobox" id="QuestionType" style="width: 200px;">
            <option value="1">文字题</option>
            <option value="2">图片题</option>
            <option value="3">视频题</option>
        </select>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        问题描述：<input type="text" class="easyui-text" id="Content"/>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <a id="searchBtn" class="easyui-linkbutton" iconcls="icon-search">查 询</a>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </fieldset>
</div>
<div>
    <table id="tab_list"></table>
</div>
